﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;

namespace JqueryNet.FormControl.FormWebControl
{
    public class JFileUpload : JWebControl
    {
        FileUpload fileupload;
        public JFileUpload(FileUpload fileupload)
            : base(fileupload)
        {
            this.fileupload = fileupload;            
        }

        public override void Val()
        {
            Value = fileupload.FileName;            
        }

        public override void Attr(string key)
        {
            switch (key.ToLower())
            {
                case "filename":
                case "file":
                    Value= fileupload.FileName;
                    return;
                case "title":
                case "tooltip":
                    Value = fileupload.ToolTip;
                    return;
                case "width":
                    Value = fileupload.Width;
                    return;
                default:
                    base.Attr(key);return;
            }
            
        }

        public override void Attr(string key, string value)
        {
            switch (key.ToLower())
            {
                case "title":
                case "tooltip":
                    Value = fileupload.ToolTip;
                    return;
                case "width":
                    Value = fileupload.Width;
                    return;
                default:
                      base.Attr(key, value);return;
            }          
        }

        public override void Val(string value)
        {
            fileupload.SaveAs(value);
        }

        public override void Val(string[] values)
        {
            foreach (var item in values)
            {
                Val(item);
            }
        }
    }
}
